package cn.cvs.interceptor;

import cn.cvs.pojo.TSysUser;
import cn.cvs.utils.Constants;
import org.apache.ibatis.plugin.Intercepts;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class SysInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.err.println(">>>>>>>>>>>进入了自定义拦截器SysInterceptor");
        TSysUser user = (TSysUser) request.getSession().getAttribute(Constants.userSession);
        if (null == user)
        {
            request.getSession().setAttribute("error","请先登录");
            response.sendRedirect(request.getContextPath()+"/user/toLogin");
            return false;
        }
        return true;//所有请求都放行
    }
}
